<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>信息修改</title>
    <link href="favicon.ico" rel="shortcut icon" />
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.4.0/css/bootstrap.min.css" rel="stylesheet">
	<style type="text/css">
        .modal-content {
            width: 350px;
            height: 350px;
            margin: 0 auto;
        }

    </style>
</head>
<body style=" background: url(http://seopic.699pic.com/photo/50050/9906.jpg_wh1200.jpg) no-repeat center center fixed; background-size: 100%;">
 
 
    <div class="modal-dialog" style="margin-top: 10%;">


        <form id="form">
            <input type="text" id="uid" name="uid" style="display: none">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title text-center" id="myModalLabel">信息修改</h4>
                </div>
                <div class="modal-body" id = "model-body">
                    <div class="form-group">
                        <input type="text" class="form-control" readonly id="username" name="username" autocomplete="off">
                    </div>
                    <div class="form-group">
                        <input type="password" class="form-control" name="password" id="newpassword" placeholder="新密码" autocomplete="off">
                    </div>
                    <div class="form-group">
                        <input type="password" class="form-control" id="confirmNewPassword" placeholder="确认您的新密码" autocomplete="off"">
                    </div>
                </div>
                <div class="modal-footer">
                    <div class="form-group">
                        <button type="button" class="btn btn-primary form-control" id="confirm">确认</button>
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-default form-control">取消</button>
                    </div>
                </div>
            </div><!-- /.modal-content -->
        </form>
    </div><!-- /.modal -->
    <script src="./js/jquery-3.4.1.min.js"></script>
    <script>
        var uid;
        var username;
        var status;
        //通过ajax获取对应用户的uid和username
        $(document).ready(function() {

            $.ajax({
                type: "GET",
                url: "http://localhost:8080/ycumall/api/admin.do?method=getUserInfo",
                dataType: "json",//返回的数据类型
                data:$("#form").serialize(),// 序列化表单值
                async: false,
                success: function (result) {
                    if (result.status === 200) {
                        //如果成功查找,json。
                        uid = result.data.uid;
                        username = result.data.username;
                        //这里需要默认传递对应用户的Uid进行传值才能修改密码
                        $("#uid").val(uid);
                        $("#username").val(username)
                    }
                    //通过jquery方式获取table，输出到特定的表单中
                },
                error: function (result) {
                    if(result.status == 404)
                        alert("查询失败！");
                }
            });
        })

        function jy() {
            $.ajax({
                type: "GET",   //提交的方法
                url: "http://localhost:8080/ycumall/api/admin.do?method=updateUser", //提交的地址
                data: $('#form').serialize(),// 序列化表单值
                async: false,
                success: function (data) {  //成功
                    // alert(data);
                    window.location.href="index.html";
                    alert('您修改密码成功');
                }
            });
        }

        $("#confirm").click(function () {
            var word1 = document.getElementById("newpassword").value;
            var word2 = document.getElementById("confirmNewPassword").value;
            if (word1 != word2) {
                alert("两次输入的新密码不一致！,请您重新输入");
                window.location.href="updateuser.html";
            } else {
                jy();
            }
        })
    </script>

</body>
</html>
